<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="活动日期">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="活动名称" prop="activityName">
        <el-input
          v-model="queryParams.activityName"
          placeholder="请输入活动名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属场站" prop="stationName">
        <el-input
          v-model="queryParams.stationName"
          placeholder="请输入所属场站"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5" v-if="station_btn">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ledger:education:add']"
        >新增</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="educationList" :max-height="tableHeight" @selection-change="handleSelectionChange">
      <el-table-column label="活动名称" align="left" prop="activityName" />
      <el-table-column label="活动日期" align="center" prop="activityDate" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.activityDate | dateString('YYYY-MM-DD') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="活动地点" align="left" prop="activityPlace" :show-overflow-tooltip="true"/>
      <el-table-column label="参加对象" align="center" prop="activityParticipant" />
      <el-table-column label="主持人" align="center" prop="activityHost" />
      <el-table-column label="记录人" align="center" prop="activityNoteTaker" />
      <el-table-column label="应到人数" align="center" prop="toBePeople" />
      <el-table-column label="实到人数" align="center" prop="toPeople" />
      <el-table-column label="所属场站" align="left" prop="stationName" width="300" v-if="!station_btn"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >详细</el-button>
          <!--<el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ledger:education:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ledger:education:remove']"
          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改安全教育活动台账对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="活动名称" prop="activityName">
          <el-input v-model="form.activityName" placeholder="请输入活动名称" maxlength="20"  show-word-limit/>
        </el-form-item>
        <el-form-item label="地 点" prop="activityPlace">
          <el-input v-model="form.activityPlace" placeholder="请输入地点" maxlength="50"  show-word-limit/>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="活动日期" prop="activityDate">
              <el-date-picker clearable size="small" style="width: 100%"
                v-model="form.activityDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择活动日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="参加对象" prop="activityParticipant">
              <el-input v-model="form.activityParticipant" placeholder="请输入参加对象" maxlength="30"  show-word-limit/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="主持人" prop="activityHost">
              <el-input v-model="form.activityHost" placeholder="请输入主持人" maxlength="15"  show-word-limit/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="记录人" prop="activityNoteTaker">
              <el-input v-model="form.activityNoteTaker" placeholder="请输入记录人" maxlength="15"  show-word-limit/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
<!--            <div class="people-to">-->
<!--              <el-form-item class="to-item" label="应到人数" prop="toBePeople">-->
<!--                <el-input :disabled="true" v-model="form.toBePeople" placeholder="请输入应到人数" />-->
<!--              </el-form-item>-->
<!--              <div @click="selectAttendWorker()" class="to-search" v-if="form.id != null">-->
<!--                <span class="el-icon-search"></span>-->
<!--              </div>-->
<!--              <div @click="selectNoAttendWorker()" class="to-search" v-else>-->
<!--                <span class="el-icon-search"></span>-->
<!--              </div>-->
<!--            </div>-->
            <el-form-item class="to-item" label="应到人数" prop="toBePeople">
              <el-input-number v-model="form.toBePeople" style="width: 120%" placeholder="请输入应到人数" controls-position="right" :min="0"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实到人数" prop="toPeople">
              <el-input-number v-model="form.toPeople" style="width: 100%" placeholder="请输入实到人数" controls-position="right" :min="0" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="安全教育主题" prop="activityTheme">
          <el-input v-model="form.activityTheme" placeholder="请输入安全教育主题" maxlength="50"  show-word-limit/>
        </el-form-item>
        <el-form-item label="安全教育内容" prop="activityContent">
          <el-input type="textarea"  v-model="form.activityContent" placeholder="请输入安全教育内容" />
        </el-form-item>
        <el-col :span="24">
          <el-form-item label="上传图片">
            <el-upload
              :multiple="true"
              accept=".jpg, .png, .gif, .bmp, .jpeg"
              :headers="upload.headers"
              :action="upload.url"
              :file-list="form.imgList"
              list-type="picture-card"
              :limit="upload.limit"
              :before-upload="beforeImageUpload"
              :on-exceed="exceedFile"
              :on-success="handlePictureSuccess"
              :on-preview="handlePictureCardPreview"
              :on-remove="handleRemove">
              <i class="el-icon-plus"></i>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png/bmp/jpeg文件，且不超过10M</div>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>

    <el-dialog title="选择出席人员" :visible.sync="openNoAttendWorker" width="800px">
      <el-form :model="queryWorkerParams" ref="queryWorkerForm" :inline="true" label-width="68px">
        <el-form-item label="姓名" prop="name" :width="150">
          <el-input
            v-model="queryWorkerParams.name"
            placeholder="请输入姓名"
            clearable
            size="small"
            @keyup.enter.native="handleWorkerQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleWorkerQuery">搜索</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="noAttendLoading" ref="noAttendWorkerTable" :data="noAttendWorkerList" @selection-change="handleNoAttendSelectionChange">
        <el-table-column type="selection" width="55" align="center" prop="workerId" />
        <el-table-column label="姓名" align="center" prop="name" />
        <el-table-column label="手机号码" align="center" prop="phone" />
      </el-table>

      <pagination
        v-show="noAttendTotal>0"
        :total="noAttendTotal"
        :page.sync="queryWorkerParams.pageNum"
        :limit.sync="queryWorkerParams.pageSize"
        @pagination="SelectNoAttendWorkerList"
      />

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sbumitAttendWorker" v-if="form.id != null">确 定</el-button>
        <el-button type="primary" @click="sbumitNoAttendWorker" v-else >确 定</el-button>
        <el-button @click="openNoAttendWorker=false">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="出席人员" :visible.sync="openAttendWorker" width="800px">
      <el-form :model="queryAttendWorkerParams" ref="queryAttendWorkerForm" :inline="true" label-width="68px">
        <el-form-item label="姓名" prop="name" :width="150">
          <el-input
            v-model="queryAttendWorkerParams.name"
            placeholder="请输入姓名"
            clearable
            size="small"
            @keyup.enter.native="handleAttendWorkerQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleAttendWorkerQuery">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleWorkerAdd"
          >新增</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="attendLoading" :data="attendWorkerList">
        <el-table-column label="姓名" align="center" prop="name" />
        <el-table-column label="手机号码" align="center" prop="phone" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleAttendWorkerDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="attendTotal>0"
        :total="attendTotal"
        :page.sync="queryAttendWorkerParams.pageNum"
        :limit.sync="queryAttendWorkerParams.pageSize"
        @pagination="selectAttendWorkerList"
      />

      <div slot="footer" class="dialog-footer">
        <el-button @click="openAttendWorker=false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 详情 -->
    <el-dialog :title="title" :visible.sync="openView" width="800px">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5" style="float:right;">
          <el-button
            type="warning"
            icon="el-icon-download"
            size="mini"
            @click="handleViewExport(id)"
          >导出</el-button>
          <el-button
            type="primary"
            icon="el-icon-printer"
            size="mini"
            @click="printPreview()"
          >打印</el-button>
        </el-col>
      </el-row>
      <el-form ref="form" id="print" :model="form" :rules="rules" label-width="120px">
        <div class="div-view">
          <h2>道路货运站（场）安全教育活动记录</h2>
          <el-row :gutter="10" class="mb8">
            <span style="float: right;padding-right:10px;line-height: 28px;">{{form.activityDate | dateString('YYYY 年 MM 月 DD 日') }} &nbsp;&nbsp; {{form.activityWeek}}</span>
          </el-row>
          <table class="sheet_table">
            <tr>
              <td>活动名称</td>
              <td colspan="3" style="text-align: left;">{{form.activityName}}</td>
            </tr>
            <tr>
              <td>地  点</td>
              <td colspan="3" style="text-align: left;">{{form.activityPlace}}</td>
            </tr>
            <tr>
              <td>参加对象</td>
              <td colspan="3" style="text-align: left;">{{form.activityParticipant}}</td>
            </tr>
            <tr>
              <td width="17%;">主持人</td>
              <td width="33%;">{{form.activityHost}}</td>
              <td width="17%;">记录人</td>
              <td width="33%;">{{form.activityNoteTaker}}</td>
            </tr>
            <tr>
              <td>应到人数</td>
              <td>{{form.toBePeople}}</td>
              <td>实到人数</td>
              <td>{{form.toPeople}}</td>
            </tr>
            <tr>
              <td>安全教育主题内容</td>
              <td colspan="3" style="text-align: left;">{{form.activityTheme}}</td>
            </tr>
            <tr>
              <td colspan="4">安 全 教 育 内 容 记 录</td>
            </tr>
            <tr>
              <td colspan="4" style="text-align: left;">
                <div style="min-height: 100px;">
                {{form.activityContent}}
                </div>
              </td>
            </tr>
            <tr v-if="form.imgList && form.imgList.length > 0 ">
              <td colspan="4">照 片</td>
            </tr>
            <tr v-if="form.imgList && form.imgList.length > 0 ">
              <td colspan="4" style="text-align: left;">
                <ul>
                  <li v-for="img in form.imgList" style="text-align: center;">
                    <el-image :preview-src-list="srcList" :src="img.url" style="width: 100px;height:100px;"></el-image>
                  </li>
                </ul>
              </td>
            </tr>
          </table>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openView = false">关 闭</el-button>
      </div>
    </el-dialog>

    <!--<x-people :showPeople.sync="isShowPeople"/>-->
  </div>
</template>

<script>
import { listEducation, getEducation, delEducation, addEducation, updateEducation, exportEducation, SelectNoAttendWorkerList, selectAttendWorkerList, deleteAttendWorker, addAttendWorker,selectNoAttendees,selectAttendees, exportEducationDetail } from "@/api/ledger/education";
/*import XPeople from '@/components/xpeoplelist';*/
import { getToken } from "@/utils/auth";
import { getLodop } from '@/utils/C-Lodop/LodopFuncs';

export default {
  name: "Education",
  data() {
    return {
      // 遮罩层
      loading: true,
      noAttendLoading: true,
      attendLoading: true,
      // 选中数组
      ids: [],
      // 选中数组
      selectWorkerIds: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      noAttendTotal: 0,
      attendTotal: 0,
      // 安全教育活动台账表格数据
      educationList: [],
      noAttendWorkerList: [],
      attendWorkerList: [],
      srcList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openView: false,
      openNoAttendWorker: false,
      openAttendWorker: false,
      station_btn: false,
      tableHeight: window.innerHeight - 275,
      //日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stationId: undefined,
        activityName: undefined,
        stationName: undefined,
      },
      queryWorkerParams: {
        pageNum: 1,
        pageSize: 10,
        ledgerId: undefined,
        name: undefined,
      },
      queryAttendWorkerParams: {
        pageNum: 1,
        pageSize: 10,
        ledgerId: undefined,
        name: undefined,
      },
      upload: {
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/common/upload",
        //  文件个数
        limit: 5
      },
      isShowPeople:false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        activityDate: [
          { required: true, message: "活动日期不能为空", trigger: "blur" }
        ],
      },
      dialogImageUrl: '',
      dialogVisible: false
    };
  },
  /*components: {
    XPeople
  },*/
  created() {
    const stationId = this.$route.params && this.$route.params.stationId;
    this.queryParams.stationId=stationId;
    const stationName = this.$route.params && this.$route.params.stationName;
    this.queryParams.stationName=stationName;
    this.getList();

    const roles = this.$store.getters && this.$store.getters.roles;
    for (let rol of roles){
      if ('station'==rol || 'hs_station'==rol){
        this.station_btn=true;
      }
    }
  },
  methods: {
    /** 查询安全教育活动台账列表 */
    getList() {
      this.loading = true;
      listEducation(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.educationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    SelectNoAttendWorkerList() {
      this.noAttendLoading = true;
      this.queryWorkerParams.ledgerId = this.form.id;
      SelectNoAttendWorkerList(this.queryWorkerParams).then(response => {
      //selectNoAttendees(this.queryWorkerParams).then(response => {
        this.noAttendWorkerList = response.rows;
        this.noAttendTotal = response.total;
        this.noAttendLoading = false;
        this.$nextTick(function () {
          this.noAttendWorkerList.forEach((item, i) => {
            this.form.workerIds.forEach((selectItem, j) => {
              if(this.noAttendWorkerList[i].workerId == this.form.workerIds[j]){
                this.$refs.noAttendWorkerTable.toggleRowSelection(this.noAttendWorkerList[i], true);
              }
            })
          })
        })
      });
    },
    selectAttendWorkerList() {
      this.attendWorkerList=[];
      this.attendLoading = true;
      this.queryAttendWorkerParams.ledgerId = this.form.id;
       selectAttendWorkerList(this.queryAttendWorkerParams).then(response => {
      //selectAttendees(this.queryAttendWorkerParams).then(response => {
        this.attendWorkerList = response.rows;
        this.attendTotal = response.total;
        this.attendLoading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        stationId: undefined,
        activityDate: undefined,
        activityWeek: undefined,
        activityName: undefined,
        activityPlace: undefined,
        activityParticipant: undefined,
        activityHost: undefined,
        activityNoteTaker: undefined,
        toBePeople: undefined,
        toPeople: undefined,
        activityTheme: undefined,
        activityContent: undefined,
        delFlag: undefined,
        createTime: undefined,
        createId: undefined,
        updateTime: undefined,
        updateId: undefined,
        remark: undefined,
        workerIds: [],
        imgList: [],
        imgs:[],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleWorkerQuery() {
      this.queryWorkerParams.pageNum = 1;
      this.SelectNoAttendWorkerList();
    },
    handleAttendWorkerQuery() {
      this.queryAttendWorkerParams.pageNum = 1;
      this.selectAttendWorkerList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    handleNoAttendSelectionChange(selection) {
      this.selectWorkerIds = [];
      this.selectWorkerIds = selection.map(item => item.workerId);
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加安全教育活动台账";
    },
    handleWorkerAdd() {
      this.resetForm("queryWorkerForm");
      this.selectWorkerIds=[];
      this.noAttendWorkerList=[];
      this.SelectNoAttendWorkerList();
      this.openNoAttendWorker = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getEducation(id).then(response => {
        this.form = response.data;
        const imgs = [];
        this.form.imgList.map(function (item) {
          imgs.push(item.url);
        });
        this.form.imgs = imgs;
        this.open = true;
        this.title = "修改安全教育活动台账";
      });
    },
    handleView(row) {
      this.reset();
      const id = row.id || this.ids
      getEducation(id).then(response => {
        this.id = row.id;
        this.form = response.data;
        const imgs = [];
        this.form.imgList.map(function (item) {
          imgs.push(item.url);
        });
        this.srcList = imgs;
        this.openView = true;
        this.title = "安全教育活动台账详情";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateEducation(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addEducation(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除该条安全教育活动台账的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delEducation(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    handleAttendWorkerDelete(row) {
      const id = row.id
      this.$confirm('是否确认删除该出席人员?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return deleteAttendWorker(id);
      }).then(() => {
        this.selectAttendWorkerList();
        if(this.form.toBePeople > 0){
          this.form.toBePeople = this.form.toBePeople - 1;
        }
        this.msgSuccess("删除成功");
      }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有安全教育活动台账数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportEducation(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
    beforeImageUpload(file){
      const isLt2M = file.size / 1024 / 1024 < 10
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 10MB!')
        return false
      }
    },
    exceedFile(files, fileList) {
      this.$notify.warning({
        title: '警告',
        message: `最多只能上传${this.upload.limit}个图片`
      });
    },
    //图片上传
    handleRemove(file, fileList) {
      this.form.imgs.splice(this.form.imgs.indexOf(file.url),1);
      // this.form.imgList.splice(this.form.imgList.indexOf(file.url),1);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handlePictureSuccess(response, file) {
      this.form.imgs.push(response.fileName);
      // this.form.imgList.push({
      //   url: response.fileName
      // });
    },
    selectNoAttendWorker(){
      this.resetForm("queryWorkerForm");
      this.noAttendWorkerList=[];
      this.SelectNoAttendWorkerList();
      this.openNoAttendWorker = true;
    },
    sbumitNoAttendWorker() {
      if(this.selectWorkerIds && this.selectWorkerIds.length > 0){
        this.form.workerIds = this.selectWorkerIds;
        this.form.toBePeople = this.selectWorkerIds.length;
        this.openNoAttendWorker = false;
      }else{
        this.msgSuccess("至少选择一个人员");
      }
    },
    selectAttendWorker(){
      this.resetForm("queryAttendWorkerForm");
      this.selectAttendWorkerList();
      this.openAttendWorker = true;
    },
    sbumitAttendWorker() {
      if(this.selectWorkerIds && this.selectWorkerIds.length > 0){
        // 添加人员
        const data = {id:this.form.id,workerIds:this.selectWorkerIds}
        addAttendWorker(data).then(response => {
          if (response.code === 200) {
            this.msgSuccess("新增成功");
            this.selectAttendWorkerList();
          } else {
            this.msgError(response.msg);
          }
        });
        this.form.toBePeople = this.form.toBePeople + this.selectWorkerIds.length;
        this.openNoAttendWorker = false;
      }else{
        this.msgSuccess("至少选择一个人员");
      }
    },
    /** 导出详情操作 */
    handleViewExport(id) {
      this.$confirm('是否确认导出该条安全教育活动台账数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportEducationDetail(id);
      }).then(response => {
        this.download(response.msg);
      }).catch(function() {});
    },
    // 打印
    printPreview() {
      this.CreateOneFormPage()
      // LODOP.PRINT() //打印预览
      LODOP.PREVIEW() //打印预览
    },
    CreateOneFormPage() {
      LODOP = getLodop()
      //样式
      var body = this.global.meeting_style +'<body>' + document.getElementById('print').innerHTML + '</body>'
      // LODOP.PRINT_INIT('安全教育活动台账详情') //打印初始化
      // LODOP.SET_PRINT_STYLE('FontSize', 18) //设置对象风格
      // LODOP.SET_PRINT_STYLE('Bold', 1) ////设置对象风格
      // LODOP.ADD_PRINT_TEXT(50, 521, 130, 39, this.description) //增加纯文本项
      // LODOP.SET_PRINT_PAGESIZE(0, 2000, 2000, '') //设定纸张大小
      // LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', '55%')//设置缩放
      // LODOP.SET_PREVIEW_WINDOW(2, 2, 0, 0, 0, '')//设置窗口
      // LODOP.ADD_PRINT_HTM(88, 20, 2000, 2000, body) //增加超文本项
      LODOP.SET_PRINT_PAGESIZE(2, 0, 0, "A4");
      LODOP.SET_PRINT_STYLE("FontSize", 12);
      LODOP.ADD_PRINT_HTM(5, 5, "100%", "100%", body);
      LODOP.SET_SHOW_MODE("LANDSCAPE_DEFROTATED", 1);//横向时的正向显示
    }
  }
};
</script>

<style scoped lang="scss">
/*.upload-title{
    font-size: 14px;
    color: #606266;
    padding:20px;
    box-sizing: border-box;
}*/
  .people-to {
    width: 100%;
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
  }
  .to-item{
    width:calc(100% - 40px);
  }
  .to-search{
    width:40px;
    height: 36px;
    line-height:36px;
    text-align:center;
    background: #1890ff;
    color: #fff;
  }
@import '../../../assets/styles/ledger_style.scss';
</style>
